<template>
  <div>
      <el-dialog   :modelValue="dialogVisible"  title="项目选择"  width="50%"
                  :close-on-click-modal="false" :close-on-press-escape="false"
                  :show-close="false" >

          <el-table :data="projects" highlight-current-row @current-change="handleCurrentChange">
            <el-table-column prop="descr" label="项目描述" />
            <el-table-column prop="prefix" label="项目前缀" />
          </el-table>

        <template #footer>
          <div style="display: flex; flex-direction: row-reverse; ">
            <el-button @click="handleCancel">取消</el-button>
            <el-button type="primary" @click="handleOk"  style="margin: 0 10px 0 10px;" >确定</el-button>
          </div>
        </template>
      </el-dialog>
  </div>
</template>

<script>

import {ElMessage} from "element-plus";
import request from '@/utils/drawutils/request'

export default {
  name: "DlgSelectProjectPrefix",
  props:{ dialogVisible: Boolean },
  components:{},
  emits:[ "resSelectPrefix" ],

  mounted() {

  },
  computed:{

  },
  data(){
    return{
      projects: [],         // 所有的项目
      currentProject: null, // 当前选中的项目
      dlgVisibleSearch: false ,
    }
  },
  watch: {

  },
  methods:{
    async init(  ){
      let res = await request.post( "/drwproject/getallprojects" )
      if( res.code === '1' ){
          this.projects = res.data
      }      
    },

    handleOk(  ){
      if(this.currentProject) {
        this.$emit("resSelectPrefix", 1, this.currentProject.prefix)
      } else {
        ElMessage.warning('请先选择一个项目')
      }
    },

    handleCancel(){
      this.$emit("resSelectPrefix", 0)
    },

    handleCurrentChange(val) {
      this.currentProject = val;
    },
  },  // end of methods

}

</script>

<style  lang="less" scoped >
::v-deep(.el-table) {
  font-size: 16px; /* 默认是14px，这里加大到16px */
}

::v-deep(.el-table__body tr.current-row > td) {
  background-color: rgb(0, 148, 68) !important;
}

::v-deep( tbody tr:hover > td ){
  background-color: transparent !important;
}

</style>